<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>试卷管理</title>
    <link rel="shortcut icon" href="../../static/favicon.ico"
          th:href="@{/static/favicon.ico}">
    <link href="../../static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"
          th:href="@{/static/css/bootstrap.min.css(v=3.3.6) }">
    <link href="../../static/css/font-awesome.css?v=4.4.0" rel="stylesheet"
          th:href="@{/static/css/font-awesome.css(v=4.4.0) }">
    <link href="../../static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet"
          th:href="@{/static/css/plugins/bootstrap-table/bootstrap-table.min.css }">
    <link href="../../static/css/animate.css" rel="stylesheet"
          th:href="@{/static/css/animate.css }">
    <link href="../../static/css/style.css?v=4.1.0" rel="stylesheet"
          th:href="@{/static/css/style.css(v=4.1.0) }">
    <!--Bootstrap表格插件-->
    <link href="../../static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet"
          th:href="@{/static/css/plugins/bootstrap-table/bootstrap-table.min.css }">
    <!--滑动按钮-->
    <link href="../../static/css/plugins/switchery/switchery.css"
          th:href="@{/static/css/plugins/switchery/switchery.css}" rel="stylesheet">
    <!--章节插件-->
    <link rel="stylesheet" href="../../static/public/exam/jquery-collapse/css/jquery.collapse.css">
    <!-- 弹出框插件 -->
    <link href="../../static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet"
          th:href="@{/static/css/plugins/sweetalert/sweetalert.css }">
    <style type="text/css">
        /* 表格样式 */
        .table > thead > tr > th {
            text-align: center;
            color: #2a62bc;
        }

        .table > tbody > tr > td {
            text-align: center;
        }
       #paperManagementForm .col-md-2{
            padding-left: 0px;
            padding-right: 8px;
        }
    </style>
</head>
<body class="gray-bg" style="padding: 0px !important;">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox-title">
        <div class="row row-lg">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active" id="allStu"><a data-toggle="tab" href="#tab-1" aria-expanded="true">我的试卷</a>
                        </li>
                        <li class="" id="notAllStu"><a data-toggle="tab" href="#tab-2" aria-expanded="false">共享试卷</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane active">
                            <div class="panel-body">
                                <p style="color: #aaa">试卷用于组织考试，由试题或试题生成规则组成，请在以下列表中管理您的试卷</p>
                                <!--创建试卷、试卷管理按钮-->
                                <div>
                                    <div class="btn-group" role="group">
                                        <button type="button" class="btn btn-white dropdown-toggle"
                                                data-toggle="dropdown" title="创建试卷">
                                            创建试卷 <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li id="commonTestPaper" onclick="switchover(1)"><a href="#"><i
                                                    class="glyphicon glyphicon-tasks"></i>&nbsp;&nbsp; 创建普通试题</a>
                                            </li>
                                            <li id="randomTestPaper" onclick="switchover(2)"><a href="#"><i
                                                    class="glyphicon glyphicon-random"></i>&nbsp;&nbsp;&nbsp;创建随机试题</a>
                                            </li>
                                        </ul>
                                    </div>
                                    <button type="button" class="btn btn-success" title="试卷管理">试卷管理</button>
                                </div><!--END---创建试卷、试卷管理按钮-->
                                <!--创建试题-->
                                <div id="createTestPaper" class="panel panel-default"
                                     style="margin-top: 10px;display: none">
                                    <div class="panel-heading">
                                        <h4 id="createPaperTitles"> 创建普通试卷&nbsp;&nbsp;&nbsp;
                                            <small style="font-size: 13px;">每个考生的试卷为相同试题，试题在考试时可随机排序显示</small></h4>
                                    </div>
                                    <div class="panel-body">
                                        <form method="get" class="form-horizontal col-md-9 createTestPaper" id="createTestPaper_1">
                                            <!--试卷名称-->
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">
                                                    试卷名称</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="testPaperName_1" class="form-control">
                                                </div>
                                            </div>
                                            <!--试卷分类-->
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">
                                                    试卷分类</label>
                                                <div class="col-sm-8">
                                                    <div class="input-group">
                                                        <input type="text" name="classification"
                                                               class="form-control classification"
                                                               placeholder="分类">
                                                        <div class="input-group-btn">
                                                            <button type="button" class="btn btn-success">
                                                                <i class="glyphicon glyphicon-plus"></i>
                                                            </button>
                                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                            </ul>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!--试卷状态-->
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">
                                                    试卷状态</label>
                                                <div class="col-sm-8">
                                                    <input type="checkbox" name="startUsing"
                                                           class="js-switch-notable form-control"/>
                                                </div>
                                            </div>
                                            <!--管理权限-->
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">
                                                    管理权限 </label>
                                                <div class="col-sm-8">
                                                    <div class="input-group">
                                                        <input type="text" name="adminPermissions"
                                                               class="form-control adminPermissions "
                                                               placeholder="权限">
                                                        <div class="input-group-btn">
                                                            <button type="button" class="btn btn-white dropdown-toggle"
                                                                    data-toggle="dropdown">
                                                                <span class="caret"></span>
                                                            </button>
                                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                            </ul>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!--试卷总分-->
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">
                                                    试卷总分</label>
                                                <div class="col-sm-8">
                                                    <input type="text" name="totalScore" disabled="" class="form-control "
                                                           placeholder="无需填写,将自动计算,将自动填值">
                                                </div>
                                            </div>
                                            <!--章节设置-->
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">
                                                    章节设置</label>
                                                <div class="col-sm-8">
                                                    <button type="button" class="btn btn-white text-sm"
                                                            style="margin-bottom: 15px"
                                                            id="add_section_btn"><i
                                                            class="glyphicon glyphicon-plus"></i>&nbsp;添加章节
                                                    </button>
                                                    <!--章节内容-->
                                                    <!-- 折叠面板组 -->
                                                    <div class="panel-group" id="accordion" role="tablist"
                                                         aria-multiselectable="true">

                                                        <!-- 在点击增加章节时，来clone此元素，并追加到 父元素中 -->
                                                        <div class="panel panel-default">
                                                            <!-- 一组章节 -->
                                                            <div class="panel-heading blue-bg" role="tab">
                                                                <h4 class="panel-title">
                                                                    <!-- 在右上角添加关闭小图标 -->
                                                                    <button type="button" class="close"
                                                                            data-dismiss="close">
                                                                        <span>&times;</span>
                                                                    </button>
                                                                    <!-- 添加向下的小图标 caret -->
                                                                    <a role="button" class="pull-right right_caret"
                                                                       data-toggle="collapse" href="#collapseOne">
                                                                        <span class="caret"></span>
                                                                    </a>
                                                                    <!-- 增加试题按钮 -->
                                                                    <button type="button"
                                                                            class="btn btn-default btn-xs pull-right right_caret"
                                                                            data-toggle="modal">
                                                                        <span class="glyphicon glyphicon-plus">增加试题</span>
                                                                    </button>

                                                                    <!-- 输入项: 章节名称 -->
                                                                    <div class="input_field">
                                                                        <label>章节名称：</label>
                                                                        <input type="text" name="sectionName"
                                                                               class="input"/>
                                                                    </div>

                                                                </h4>
                                                            </div>
                                                            <!-- 要重写包一层 panel-heading -->
                                                            <div class="panel-heading gray-bg">
                                                                <h4 class="panel-title">
                                                                    <!-- 输入项：章节描述 -->
                                                                    <div class="input_field">
                                                                        <label class="text-muted">章节描述：</label>
                                                                        <input type="text" name="sectionDescription"
                                                                               class="input"/>
                                                                        <!-- 批量设置分值: 这里修改padding，是为了改写 btn-xs的默认样式 -->
                                                                        <a href="javascript:void(0);"
                                                                           class="btn btn-info btn-xs pull-right"
                                                                           data-trigger="setScore">批量设置</a>
                                                                        <input type="text" name="scoreForEach"
                                                                               class="input_score pull-right"
                                                                               placeholder="分值"/>
                                                                    </div>
                                                                </h4>
                                                            </div>
                                                            <!-- 内容区 -->
                                                            <div id="collapseOne" class="panel-collapse collapse in"
                                                                 role="tabpanel">
                                                                <div class="panel-body">
                                                                </div>
                                                            </div> <!-- end of 内容区 -->
                                                        </div><!-- end of panel -->
                                                    </div> <!-- end of panel-group --> <!--END--章节内容-->
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                    <!--提交和重新填写的两个按钮-->
                                    <div class="col-md-offset-6" style="padding: 10px">
                                        <button type="button" class="btn btn-success add">提交</button>
                                        <button type="button" class="btn btn-danger reset">重新填写</button>
                                    </div>
                                    <!--END--提交和重新填写的两个按钮-->
                                </div><!--END---创建试题-->
                                <!--题库管理-->
                                <div id="topicManagement">
                                    <!--右上角form表单-->
                                    <div id="toolbar">
                                        <form class="form-inline" id="paperManagementForm">
                                            <!-- 试卷名称-->
                                            <div class="col-md-2">
                                            <div class="form-group">
                                                <div class="input-group ">
                                                    <input type="text" name="testPaperName"
                                                           class="form-control testPaperName"
                                                           placeholder="试卷名称">
                                                    <div class="input-group-btn">
                                                        <button type="button" class="btn btn-white dropdown-toggle"
                                                                data-toggle="dropdown">
                                                            <span class="caret"></span>
                                                        </button>
                                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                            <!--状态-->
                                            <div class="col-md-2">
                                            <div class="form-group">
                                                <div class="input-group ">
                                                    <input type="text" name="state" class="form-control state"
                                                           placeholder="状态">
                                                    <div class="input-group-btn">
                                                        <button type="button" class="btn btn-white dropdown-toggle"
                                                                data-toggle="dropdown">
                                                            <span class="caret"></span>
                                                        </button>
                                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                            <!--分类-->
                                            <div class="col-md-2">
                                            <div class="form-group ">
                                                <div class="input-group">
                                                    <input type="text" name="classification"
                                                           class="form-control classification"
                                                           placeholder="分类">
                                                    <div class="input-group-btn">
                                                        <button type="button" class="btn btn-white dropdown-toggle"
                                                                data-toggle="dropdown">
                                                            <span class="caret"></span>
                                                        </button>
                                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                            <!--类型-->
                                            <div class="col-md-2">
                                            <div class="form-group ">
                                                <div class="input-group">
                                                    <input type="text" name="type" class="form-control type"
                                                           placeholder="类型">
                                                    <div class="input-group-btn">
                                                        <button type="button" class="btn btn-white dropdown-toggle"
                                                                data-toggle="dropdown">
                                                            <span class="caret"></span>
                                                        </button>
                                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                            <!--权限-->
                                            <div class="col-md-2">
                                            <div class="form-group ">
                                                <div class="input-group">
                                                    <input type="text" name="class"
                                                           class="form-control adminPermissions"
                                                           placeholder="权限">
                                                    <div class="input-group-btn">
                                                        <button type="button" class="btn btn-white dropdown-toggle"
                                                                data-toggle="dropdown">
                                                            <span class="caret"></span>
                                                        </button>
                                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                            </div>
                                            <!--查询按钮-->
                                            <button class="btn btn-success query" type="button"><i
                                                    class="glyphicon glyphicon-search"></i></button>
                                        </form>
                                    </div><!--END--右上角form表单-->
                                    <table class="tb_departments"></table>
                                </div> <!--END---题库管理-->
                            </div>

                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="panel-body">
                                <p style="color: #aaa">共享试卷是由各管理员创建并 共享 给所有管理员使用的试卷，您可以使用这些试卷组织考试</p>
                                <!--右上角form表单-->
                                <div id="toolbar_1">
                                    <form class="form-inline" id="shareTestPaperFrom">
                                        <!-- 试卷名称-->
                                        <div class="form-group">
                                            <div class="input-group ">
                                                <input type="text" name="testPaperName"
                                                       class="form-control testPaperName"
                                                       placeholder="试卷名称">
                                                <div class="input-group-btn">
                                                    <button type="button" class="btn btn-white dropdown-toggle"
                                                            data-toggle="dropdown">
                                                        <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                        <!--类型-->
                                        <div class="form-group ">
                                            <div class="input-group">
                                                <input type="text" name="classification"
                                                       class="form-control classification"
                                                       placeholder="分类">
                                                <div class="input-group-btn">
                                                    <button type="button" class="btn btn-white dropdown-toggle"
                                                            data-toggle="dropdown">
                                                        <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                        <!--创建人-->
                                        <div class="form-group ">
                                            <input type="text" name="founder"
                                                   class="form-control founder"
                                                   placeholder="创建人">
                                        </div>
                                        <!--查询按钮-->
                                        <button class="btn btn-success query" type="button"><i
                                                class="glyphicon glyphicon-search"></i></button>
                                    </form>
                                </div><!--END--右上角form表单-->
                                <table class="tb_departments_1"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 章节设置里的模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">选择题库</h4>
            </div>
            <div class="modal-body">
                利用相关组件来呈现题库
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="myModalBatchAddBtn">批量插入</button>
            </div>
        </div>
    </div>
</div>
<!--查看的模态框-->
<div class="modal  fade" id="modal_1" tabindex="-1" role="dialog" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">试卷预览</h4>
            </div>
            <div class="modal-body">
                <form method="get" class="form-horizontal" id="form_toView">
                    <div class="form-group">
                        <label class="col-sm-2 control-label ">
                            试卷名称</label>
                        <div class="col-sm-8">
                            <input type="text" name="testPaperName" disabled="" class="form-control testPaperName_1" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                            试卷状态</label>
                        <div class="col-sm-8">
                            <input type="text" name="state" disabled="" class="form-control state_1 " placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                            管理权限</label>
                        <div class="col-sm-8">
                            <input type="text" name="adminPermissions" disabled="" class="form-control adminPermissions_1" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                            试卷总分</label>
                        <div class="col-sm-8">
                            <input type="text" name="totalScore" disabled="" class="form-control totalScore" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                            章节设置</label>
                        <div class="col-sm-8">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <strong>章节名称：</strong><a class="nameSection"></a>
                                </div>
                                <table class="table table-bordered">
                                    <tr>
                                        <td>题库</td>
                                        <td>题型</td>
                                        <td>难度</td>
                                        <td>题目数量</td>
                                        <td>单题分值</td>
                                    </tr>
                                    <tr>
                                        <td><a class="questionBank"></a></td>
                                        <td><a class="topic"></a></td>
                                        <td><a class="difficulty"></a></td>
                                        <td><a class="titleNumber"></a></td>
                                        <td><a class="singleTopicScore"></a></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<!--关联考试的模态框-->
<div class="modal  fade" id="modal_2" tabindex="-1" role="dialog" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">关联的考试</h4>
            </div>
            <div class="modal-body">
                <p style="color: #aaa">试卷&nbsp;<a class="testPaperName_2"></a>&nbsp;被如下列表中的考试所引用</p>
                <table class="tb_departments_2"></table>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 全局js -->
<script src="../../static/js/jquery.min.js?v=2.1.4"
        th:src="@{/static/js/jquery.min.js(v=2.1.4) }"></script>
<script src="../../static/js/bootstrap.min.js?v=3.3.6"
        th:src="@{/static/js/bootstrap.min.js(v=3.3.6) }"></script>
<!-- 自定义js -->
<script src="../../static/js/content.js?v=1.0.0"
        th:src="@{/static/js/content.js(v=1.0.0) }"></script>
<!--Bootstrap表格插件 -->
<script src="../../static/js/plugins/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/static/js/plugins/bootstrap-table/bootstrap-table.min.js }"></script>
<script src="../../static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"
        th:src="@{/static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js }"></script>
<script src="../../static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
        th:src="@{/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js }"></script>
<!--滑动按钮-->
<script src="../../static/js/plugins/switchery/switchery.js"
        th:src="@{/static/js/plugins/switchery/switchery.js}"></script>
<!--动态搜索-->
<script src="../../static/js/plugins/suggest/bootstrap-suggest.min.js"
        th:src="@{/static/js/plugins/suggest/bootstrap-suggest.min.js}"></script>
<script src="../../static/public/user/bsSuggest.js"
        th:src="@{/static/public/user/bsSuggest.js }"></script>
<!--章节插件-->
<script src="../../static/public/exam/jquery-collapse/js/jquery.collapse.js"
        th:src="@{/static/public/exam/jquery-collapse/js/jquery.collapse.js }"></script>
<!-- 弹出框插件 -->
<script src="../../static/js/plugins/sweetalert/sweetalert.min.js"
        th:src="@{/static/js/plugins/sweetalert/sweetalert.min.js }"></script>
<!--自定义js---表格操作-->
<script src="../../static/public/exam/tableOperation.js"
        th:src="@{/static/public/exam/tableOperation.js}"></script>
<!--滑动按钮初始化、创建试卷按钮监听、文章内容-->
<script>
    $(function () {
        switchForNoTable();
    });
    let checked_notable = false;
    /* 初始化非表格中的滑动按钮状态*/
    function switchForNoTable() {
        let elems = Array.prototype.slice.call($('.js-switch-notable'));
        elems.forEach(function (html) {
            /* size: 'normal' 控制大小*/
            let switchery = new Switchery(html);
            html.onchange = function () {
               checked_notable = html.checked;
            }
        });
    }

    $('#tab-1 button[title="试卷管理"]').click(function () {
        $('#topicManagement').css('display', 'block');
        $('#createTestPaper').css('display', 'none');
        $('#tab-1 button[title="试卷管理"]').attr('class', 'btn btn-success dropdown-toggle')
        $('#tab-1 button[title="创建试卷"]').attr('class', 'btn btn-white dropdown-toggle')
    });

    /*文章内容*/
    $("#add_section_btn").collapsePanel({
        "review": function (id) {
            alert("你要预览的数据id是：" + id);
        },
        /*
        "delete": function (target) {
            //此属性在插件中已经实现，如果你想要换成其它的实现，则可以在此重写
        }*/
        "batchInsertId": "#myModalBatchAddBtn",
        "method": "post",
        "itemDatas": "json/data.json",
        "formatter": function (id) {
            return [
                "<button type='button' class='btn btn-default' data-trigger='review' data-id='" + id + "'><i class='glyphicon glyphicon-eye-open'></i></button>",
                "<button type='button' class='btn btn-default ' data-trigger='delete'><i class='glyphicon glyphicon-remove'></i></button>"
            ].join("");
        }
    });
</script>
<!--表单、动态搜索初始化-->
<script>

    /*动态搜索初始化*/
    let url = '../../static/js/demo/exam/testQuestionsListTest2.json';
    //名称
    bsSuggest(".testPaperName", url, "testPaperName");
    //状态
    bsSuggest(".state", url, "state");
    //分类
    bsSuggest(".classification", url, "classification");
    //类型
    bsSuggest(".type", url, 'type');
    //权限
    bsSuggest(".adminPermissions", url, "adminPermissions");

    /**************************************************表单********************************************/
    //我的试卷--试卷管理
    $('#paperManagementForm .query').click(function () {
        let testPaperName = $('#paperManagementForm input[name="testPaperName"]').val();
        let state = $('#paperManagementForm input[name="state"]').val();
        let classification = $('#paperManagementForm input[name="classification"]').val();
        let type = $('#paperManagementForm input[name="type"]').val();
        let adminPermissions = $('#paperManagementForm input[name="adminPermissions"]').val();
        if (testPaperName == "" || state == "" || classification == ""||type == ""||adminPermissions == ""){
            swal("搜索失败！", "不允许有空数据", "error");
            return false;
        }
        let obj = {
            "testPaperName":testPaperName,
            "state":state,
            "classification":classification,
            "type":type,
            "adminPermissions":adminPermissions,
        }
        let query_data = JSON.stringify(obj);
        alert(query_data);
        /* //发送ajax 查询
            $.ajax({
                url: appName+"/book/deleteSelect.do",
                method: "post",
                async: true,
                data: query_data,
                dataType: "text",   //期望服务端返回的数据类型
                contentType: "application/json",
                success: function (data) {
                    console.log(data.toString());
                    //重新加载页面
                    $('#tb_departments').bootstrapTable('load', data);
                },
                error: function (jqXHR) {
                    swal("搜索失败！", "未知错误", "error");
                }
            });*/
        swal("搜索成功！", "已为你重新加载数据", "success");
    });
    //共享试卷
    $('#shareTestPaperFrom .query').click(function () {
        let testPaperName = $('#shareTestPaperFrom input[name="testPaperName"]').val();
        let classification = $('#shareTestPaperFrom input[name="classification"]').val();
        let founder = $('#shareTestPaperFrom input[name="founder"]').val();
        if (testPaperName == "" ||  classification == ""||founder == ""){
            swal("搜索失败！", "不允许有空数据", "error");
            return false;
        }
        let obj = {
            "testPaperName":testPaperName,
            "classification":classification,
            "founder":founder,
        }
        let query_data = JSON.stringify(obj);
        alert(query_data);
        /* //发送ajax 查询
            $.ajax({
                url: appName+"/book/deleteSelect.do",
                method: "post",
                async: true,
                data: query_data,
                dataType: "text",   //期望服务端返回的数据类型
                contentType: "application/json",
                success: function (data) {
                    console.log(data.toString());
                    //重新加载页面
                    $('#tb_departments').bootstrapTable('load', data);
                },
                error: function (jqXHR) {
                    swal("搜索失败！", "未知错误", "error");
                }
            });*/
        swal("搜索成功！", "已为你重新加载数据", "success");
    });
    //创建试卷
    /*按钮切换*/
    function testPaper(number,addOrUpdate) {
        $('#createTestPaper').css('display', 'block');
        if (number == "1") {
            $('#createPaperTitles').html(' 创建普通试卷&nbsp;&nbsp;&nbsp;<small style="font-size: 13px;">每个考生的试卷为相同试题，试题在考试时可随机排序显示</small>');
            $('#createTestPaper form').attr('id', 'createTestPaper_1')
        } else {
            $('#createPaperTitles').html(' 创建随机试卷&nbsp;&nbsp;&nbsp;<small style="font-size: 13px;">每个考生的试卷为系统随机生成，考生试卷中的试题各不相同</small>');
            $('#createTestPaper form').attr('id', 'createTestPaper_2')
        }
        $('#topicManagement').css('display', 'none');
        $('#tab-1 button[title="创建试卷"]').attr('class', 'btn btn-success dropdown-toggle')
        $('#tab-1 button[title="试卷管理"]').attr('class', 'btn btn-white dropdown-toggle')
        //回显数据
        if(judging){
            echoData(parameters);
        }else {
            $("#createTestPaper form")[0].reset();
            $('#createTestPaper form .form-group').attr('class','form-group')
        }
        //如果是更新，则去掉按钮颜色
        addOrUpdate=="update"? $('#tab-1 button[title="创建试卷"]').attr('class', 'btn btn-white dropdown-toggle'):"";
        //重置属性状态
        judging = false;
        parameters.splice(0,parameters.length);

    }

    function switchover(number){
        judging = false;
        testPaper(number);
    }

    let parameters = new Array();
    let judging = false;
    function testOperation(addOrUpdate){
        let testPaperName = $('.createTestPaper input[name="testPaperName_1"]');
        let classification = $('.createTestPaper input[name="classification"]');
        let startUsing = checked_notable;
        let adminPermissions = $('.createTestPaper input[name="adminPermissions"]');
        let sectionName = $('.createTestPaper input[name="sectionName"]');
        let sectionDescription = $('.createTestPaper input[name="sectionDescription"]');
        let scoreForEach = $('.createTestPaper input[name="scoreForEach"]');
        //总分处理---数据回显和计算总分值
        let totalScore = scoreForEach;
        $('.createTestPaper input[name="totalScore"]').val(scoreForEach.val())
        parameters.push(testPaperName,classification,adminPermissions,sectionName,sectionDescription,scoreForEach);
        let query_data = "{";
        parameters.forEach(function (item,index) {
                item.val()==""?judging=true:"";
                let record = (parameters.length-index)!=1 ? '"'+item.attr('name')+'":'+item.val()+',':'"'+item.attr('name')+'":'+item.val();
                query_data = query_data + record;
        });
        query_data = query_data + '"+startUsing":'+startUsing+',"totalScore":'+totalScore.val();
        query_data = query_data +"}";
        console.log(query_data);
        if(addOrUpdate == "add"){
            //发送添加操作
        }else {
            //发送更新操作
        }
        /* //发送ajax 查询
            $.ajax({
                url: appName+"/book/deleteSelect.do",
                method: "post",
                async: true,
                data: query_data,
                dataType: "text",   //期望服务端返回的数据类型
                contentType: "application/json",
                success: function (data) {
                    console.log(data.toString());
                    //重新加载页面
                    $('#tb_departments').bootstrapTable('load', data);
                },
                error: function (jqXHR) {
                    swal("搜索失败！", "未知错误", "error");
                }
            });*/
        if(judging){
            swal("操作失败！", "数据不允许为空", "error");
        }else {
            addOrUpdate == "add"?  swal("提交成功！", "已为你重新加载页面", "success"): swal("更新成功！", "已为你重新加载页面", "success");
        }
        query_data = "";
        pageJudgment(addOrUpdate);
    }
    //数据回显
    function echoData(arrayForEvent){
        //准备数据
        let arrayForValue = new Map();
        let arrayIsNull = new Array();
        if (arrayForEvent.length<1){
            return false;
        }
        arrayForEvent.forEach(function (item,index) {
            item.val()!=""?arrayForValue.set(item,item.val()):arrayIsNull.push(item);
        })
        //刷新页面
        $("#createTestPaper form")[0].reset();
        //回显数据
        if (arrayForValue.size>1){
            arrayForValue.forEach(function(value,key){
                key.parents('.form-group').attr('class')=="form-group has-error"?key.parents('.form-group').attr('class','form-group'):"";
                key.val(value);
            });
        }
        if (arrayIsNull.length>1){
            arrayIsNull.forEach(function (item,index) {
                item.parents('.form-group').attr({'class':"form-group has-error"});
            })
        }
        //清空集合
        arrayForValue.clear();
        arrayIsNull.splice(0,arrayIsNull.length);
    }
    //跳转页面判断
    function pageJudgment(addOrUpdate){
        $('#createTestPaper form').attr('id')=='createTestPaper_1'?
            (addOrUpdate == "update"?testPaper(1,"update"):testPaper(1,"add")):(addOrUpdate == "update"?testPaper(2,"update"):testPaper(2,"add"));
    }

    $('#createTestPaper .add').click(function () {
        if( $('#tab-1 button[title="创建试卷"]').attr("class") != "btn btn-white dropdown-toggle"){
            testOperation("add");
        }else {
            testOperation("update");
        }
    });

    $('#createTestPaper .reset').click(function () {
        $("#createTestPaper form")[0].reset();
        $('#createTestPaper form .form-group').attr('class','form-group')
    });
    /********************************************END---表单********************************************/
</script>
<!--表格-->
<script>

    /*试卷管理表格*/
    $('.tb_departments').bootstrapTable({
        url: '../../static/js/demo/exam/testQuestionsListTest.json',
        // method: 'get',
        toolbar: '#toolbar',
        striped: true,
        cache: false,
        pagination: true,
        pageNumber: 1,
        pageSize: 5,
        pageList: [10, 25, 50, 100],
        uniqueId: "id",
        onPostBody: switchForTable,
        columns:
            [{
                checkbox: true
            }, {
                field: 'id',
                visible: false
            }, {
                title: '试卷名称',
                formatter: testPaperName
            }, {
                title: '引用次数',
                formatter: citations,
                events: {
                    'click a[title=点我查看详情]':function (e,value,row,index) {
                        $('#modal_2 .testPaperName_2').text(row.testPaperName);
                        $('#modal_2').modal();
                    }
                }
            }, {
                title: '状态',
                formatter: state
            }, {
                title: '类型',
                formatter: type,
            }, {
                field: 'classification',
                title: '分类'
            }, {
                title: '总分',
                formatter: totalScore
            }, {
                title: '管理权限',
                formatter: adminPermissions
            }, {
                title: '最后修改',
                formatter: lastModified
            }, {
                title: '操作',
                formatter: operation,
                events:{
                    /*查看*/
                    'click button[title=查看]':detailedTestPaper,  /*END--查看*/
                    /*修改*/
                    'click button[title=修改]':function (e,value,row,index) {
                        if(row.trySorting=="固定排序"){
                            testPaper(1,"update");
                        }else {
                            testPaper(2,"update");
                        }
                        let echoDataMap = new Map();
                        //key->选择器 value->数据
                        judging = false;
                    },  /*END--修改*/
                    /*删除*/
                    'click button[title=删除]':function (e,value,row,index) {
                      deleteRecord(e,value,row,index,"",'.tb_departments');
                    },  /*END--删除*/
                }
            }]
    });
    /*查看试卷的方法*/
    function detailedTestPaper(e,value,row,index){
        $('#modal_1 .testPaperName_1').val(row.testPaperName);
        row.state == "禁用" ? $('#modal_1 .state_1').attr("class", 'form-control state_1 text-danger') :
            $('#modal_1 .state_1').attr('class', 'form-control state_1 text-success');
        $('#modal_1 .state_1').val(row.state);
        if (row.adminPermissions == '0') {
            $('#modal_1 .adminPermissions_1').val("完全私有(只有您本人可以管理和使用该试卷)");
        } else {
            $('#modal_1 .adminPermissions_1').val("只读共享(其他管理员可以浏览和引用该试卷进行考试)");
        }

        $('#modal_1 .totalScore').val(row.totalScore + "分");
        $('#modal_1 .nameSection').text(row.nameSection);
        $('#modal_1 .questionBank').text(row.questionBank);
        $('#modal_1 .topic').text(row.topic);
        $('#modal_1 .difficulty').text(row.difficulty);
        $('#modal_1 .titleNumber').text(row.titleNumber);
        $('#modal_1 .singleTopicScore').text(row.singleTopicScore + "分");
        $('#modal_1').modal()

    }
    /*共享试卷表格*/
    $('.tb_departments_1').bootstrapTable({
        url: '../../static/js/demo/exam/testQuestionsListTest.json',
        // method: 'get',
        toolbar: '#toolbar_1',
        striped: true,
        cache: false,
        pagination: true,
        pageNumber: 1,
        pageSize: 5,
        pageList: [10, 25, 50, 100],
        uniqueId: "id",
        onPostBody: switchForTable_1,
        columns:
            [{
                checkbox: true
            }, {
                title: '试卷名称',
                formatter: testPaperName
            }, {
                title: '引用次数',
                formatter: citations,
                events: {
                    'click a[title=点我查看详情]':function (e,value,row,index) {
                        $('#modal_2').modal();
                    }
                }
            }, {
                title: '状态',
                formatter: state_1
            }, {
                title: '类型',
                formatter: type,
            }, {
                field: 'classification',
                title: '分类'
            }, {
                title: '总分',
                formatter: totalScore
            }, {
                title: '管理权限',
                formatter: adminPermissions
            }, {
                title: '最后修改',
                formatter: lastModified
            }, {
                title: '操作',
                formatter: operation_1,
                events: {
                    /*查看*/
                    'click button[title=查看]': detailedTestPaper,  /*END--查看*/
                }
            }]
    });

    /*关联的考试表格*/
    $('.tb_departments_2').bootstrapTable({
        url: '../../static/js/demo/exam/testQuestionsListTest.json',
        // method: 'get',
        striped: true,
        cache: false,
        pagination: true,
        pageNumber: 1,
        pageSize: 5,
        pageList: [10, 25, 50, 100],
        uniqueId: "id",
        columns:
            [{
                checkbox: true
            }, {
                title: '试卷名称',
                formatter: testPaperName
            },  {
                title: '考试时间',
                formatter: citations
            }, {
                title: '总分',
                formatter: totalScore
            },{
                title: '创建人',
                field:"modifier"
            }]
    });

    /***********************************************参数个性化********************************************/
    //试卷名称
    function testPaperName(value, row, index) {
        return '<span><i class="glyphicon glyphicon-list-alt"></i>&nbsp;&nbsp;' + row.testPaperName + '</span>';
    }

    //引用次数
    function citations(value, row, index) {
        return '<strong><a class="text-success '+row.id+'" style="font-size:20px;" title="点我查看详情">' + row.citations + '</a></strong>次';
    }

    //状态(我的试卷)
    function state(value, row, index) {
        return row.state == '正常' ? ' <input type="checkbox" class="js-switch-table-state form-control" checked/>' :
            ' <input type="checkbox" class="js-switch-table-state form-control"/>'
    }

    //状态(共享试卷)
    function state_1(value, row, index) {
        return row.state == '正常' ? ' <input type="checkbox" class="js-switch-table-state_1 form-control" checked/>' :
            ' <input type="checkbox" class="js-switch-table-state_1 form-control"/>'
    }

    //类型
    function type(value, row, index) {
        return row.type == 0 ? '<i class="glyphicon glyphicon-random"></i>' : '<i class="glyphicon glyphicon-tasks"></i>';
    }

    //总分
    function totalScore(value, row, index) {
        return row.totalScore >= 80 ? '<strong><a href="#" class="text-success" style="font-size:20px;">' + row.totalScore + '</a></strong>' :
            row.totalScore >= 60 ? '<strong><a href="#" class="text-warning" style="font-size:20px;">' + row.totalScore + '</a></strong>' :
                '<strong><a href="#" class="text-danger" style="font-size:20px;">' + row.totalScore + '</a></strong>';
    }

    //管理权限
    function adminPermissions(value, row, index) {
        return row.adminPermissions == '0' ? '<a class="text-muted"><i class="glyphicon glyphicon-eye-close"></i>&nbsp;&nbsp;完全私有</a>' :
            '<a class="text-success"><i class="glyphicon glyphicon-eye-open"></i>&nbsp;&nbsp;<strong>只读共享</strong></a>';
    }

    //最后修改
    function lastModified(value, row, index) {
        return '<strong><p>' + row.modifier + '</p></strong><p>' + row.lastModifiedTime + '</P>';
    }

    //操作
    function operation(value, row, index) {
        return '<button id = "+id+" type = "button" class = "btn btn-white" title="查看"> <i class="glyphicon glyphicon-eye-open"/> </button>' +
            '<button id = "+id+" type = "button" class = "btn btn-white" title="修改"> <i class="glyphicon glyphicon-edit text-success"/> </button>' +
            '<button id = "+id+" type = "button" class = "btn btn-white" title="删除"> <i class="glyphicon glyphicon-trash text-danger"/> </button>';
    }

    //操作
    function operation_1(value, row, index) {
        return '<button id = "+id+" type = "button" class = "btn btn-white" title="查看"> <i class="glyphicon glyphicon-eye-open"/> </button>'
    }

    //初始化滑动按钮状态(我的试卷)
    function switchForTable() {
        let elems = Array.prototype.slice.call($('.js-switch-table-state'));
        elems.forEach(function (html) {
            /* size: 'normal' 控制大小*/
            let switchery = new Switchery(html);
            html.onchange = function () {
                alert(html.checked);
            }
        });
    }

    //初始化滑动按钮状态(共享试卷)
    function switchForTable_1() {
        let elems = Array.prototype.slice.call($('.js-switch-table-state_1'));
        elems.forEach(function (html) {
            /* size: 'normal' 控制大小*/
            let switchery = new Switchery(html);
            html.onchange = function () {
                alert(html.checked);
            }
        });
    }
    /*******************************************END---参数个性化********************************************/
    /*END--题库管理表格*/
</script>
</html>